<template>

    <el-container v-show="!dialog.save">
        <el-header class="elheader">
            <!-- <div class="title">青海省中波中心台>调度令>列表</div> -->
            <div class="left-panel">
                <div class="name">中波中心调度令</div>
                <div class="fieldname">时间</div>
                <div>
                    <el-date-picker v-model="time" type="datetimerange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" />
                </div>
                <div class="fieldname">关键词</div>
                <el-input v-model="list.params.keyword" style="width:200px;" clearable />
                <div style="padding-left:10px"></div>
                <el-button type="primary" size="default" @click="upsearch">查询</el-button>
                <el-button type="primary" v-auth="'order.new'" size="default" icon="el-icon-plus" @click="orderAdd">新增</el-button>
            </div>
            <div class="tags">
                <sc-select-filter :data="filterData" :selectedValues="filterSelected" :label-width="80" @on-change="filterChange"></sc-select-filter>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="list.apiObj" row-key="ProjectID" :params="list.params" :getrowclassname="getrowclassname" stripe>
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column type="expand">
                    <template #default="scope">
                        <div v-if="ifshowchildrenrow(scope.row)" style="padding:20px;">
                            <h1>接收情况:</h1>
                            <el-table :data="scope.row.children" :stripe="true" :border="false">
                                <el-table-column width="40" />
                                <el-table-column label="台站" width="120" prop="stationName" />
                                <el-table-column label="是否接收" width="120" prop="statue">
                                    <template #default="rowdata">
                                        <div style="display:flex; width:100%;flex-direction: row;align-items: center;">
                                            <sc-status-indicator v-if="rowdata.row.statue=='已接收'" type="success" style="margin-right:5px;">
                                            </sc-status-indicator>

                                            <sc-status-indicator v-if="rowdata.row.statue=='未接收'" pulse type="danger" style="margin-right:5px;">
                                            </sc-status-indicator>

                                            <div>{{rowdata.row.statue}}</div>
                                        </div>

                                    </template>
                                </el-table-column>
                                <el-table-column label="接收人" prop="acceptUserName" width="120" />
                                <el-table-column label="接收时间" prop="acceptTime" width="160" />
                                <el-table-column label="执行人" prop="executeUserName" width="120" />
                                <el-table-column label="执行时间" prop="executeTime" width="160" />
                                <el-table-column label="测试人" prop="testUserName" width="120" />
                                <el-table-column label="测试时间" prop="testTime" width="160" />
                                <el-table-column label="操作" align="left">
                                    <template #default="scopechildren">
                                        <el-button v-auth="'order.process'" type="primary" plain size="small" :disabled="getifAccept(scope.row,scopechildren.row)" @click="accept(scope.row,scopechildren.row)">接收</el-button>
                                        <el-button v-if="getifShow_Edit('detail',scope.row.WorkflowID)" type="primary" plain size="small" :disabled="getifEdit(scope.row,scopechildren.row)" @click="table_edit(scope.row,scopechildren.row)">
                                            <div v-if="scope.row.WorkflowID>2">编制</div>
                                            <div v-else>编辑</div>
                                        </el-button>

                                        <el-popconfirm title="确定测试吗？" @confirm="test(scope.row,scopechildren.row)">
                                            <template #reference>
                                                <el-button v-auth="'order.execute'" type="primary" plain size="small" :disabled="getifTest(scope.row,scopechildren.row)">
                                                    <div v-if="scopechildren.row.testUser == undefined || scopechildren.row.testUser == ''">测试</div>
                                                    <div v-else>已测试</div>
                                                </el-button>
                                            </template>
                                        </el-popconfirm>

                                        <el-popconfirm title="确定执行吗？" @confirm="execute(scope.row,scopechildren.row)">
                                            <template #reference>
                                                <el-button v-auth="'order.execute'" type="primary" plain size="small" :disabled="getifExcute(scope.row,scopechildren.row)">
                                                    <div v-if="scopechildren.row.executeUser == undefined || scopechildren.row.executeUser == ''"> 执行</div>
                                                    <div v-else>已执行</div>
                                                </el-button>
                                            </template>
                                        </el-popconfirm>

                                        <!-- scope.row.Closed=='1'||scope.row.WorkflowID!='3' -->
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="调度文号" prop="ProjectSerrial" width="180"></el-table-column>
                <el-table-column label="调度令性质" prop="ProjectType" width="110">
                    <template #default="scope">
                        <div v-if="scope.row.ProjectType==1">正式</div>
                        <div v-if="scope.row.ProjectType==0">试验</div>
                    </template>
                </el-table-column>
                <el-table-column label="发送单位" prop="ProjectAuthor" width="80"></el-table-column>
                <el-table-column label="起草部门" prop="ProjectSenderOrg" width="80"></el-table-column>
                <el-table-column label="发送人" prop="ProjectSenderName" width="120"></el-table-column>
                <el-table-column label="审核人" prop="ProjectAuditorName" width="120">
                    <template #default="scope">
                        <div v-if="scope.row.ProjectAuditorName==''||scope.row.ProjectAuditorName==null">无</div>
                        <div v-else>{{scope.row.ProjectAuditorName.replace('(已)','').replace('(待)','')}}
                            <el-tag v-if="scope.row.ProjectAuditorName.indexOf('(已)')>0" type="success" size="mini">已</el-tag>
                            <el-tag v-if="scope.row.ProjectAuditorName.indexOf('(待)')>0" type="warning" size="mini">待</el-tag>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="审核人2" prop="ProjectAuditor2Name" width="120">
                    <template #default="scope">
                        <div v-if="scope.row.ProjectAuditor2Name==''||scope.row.ProjectAuditor2Name==null">无</div>
                        <div v-else>{{scope.row.ProjectAuditor2Name.replace('(已)','').replace('(待)','')}}
                            <el-tag v-if="scope.row.ProjectAuditor2Name.indexOf('(已)')>0" type="success" size="mini">已</el-tag>
                            <el-tag v-if="scope.row.ProjectAuditor2Name.indexOf('(待)')>0" type="warning" size="mini">待</el-tag>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="审批人" prop="ProjectSignName" width="120">
                    <template #default="scope">
                        <div v-if="scope.row.ProjectSignName==''||scope.row.ProjectSignName==null">无</div>
                        <div v-else>{{scope.row.ProjectSignName.replace('(已)','').replace('(待)','')}}
                            <el-tag v-if="scope.row.ProjectSignName.indexOf('(已)')>0" type="success" size="mini">已</el-tag>
                            <el-tag v-if="scope.row.ProjectSignName.indexOf('(待)')>0" type="warning" size="mini">待</el-tag>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="状态" prop="ProjectStatus" width="80">
                    <template #default="scope">
                        <div style="display:flex; width:100%;flex-direction: row;align-items: center;justify-content: center;">
                            <sc-status-indicator v-if="scope.row.ProjectStatus<=1" type="success" style="margin-right:5px;">
                            </sc-status-indicator>
                            <!-- <div v-if="scope.row.ProjectStatus==0">未开始</div> -->
                            <div v-if="scope.row.ProjectStatus<=1">进行中</div>
                            <sc-status-indicator v-if="scope.row.ProjectStatus>1" pulse type="danger" style="margin-right:5px;">
                            </sc-status-indicator>
                            <div v-if="scope.row.ProjectStatus==2">已归档</div>
                            <div v-if="scope.row.ProjectStatus==9">已终止</div>
                        </div>

                    </template>
                </el-table-column>
                <el-table-column label="开始时间" prop="ProjectStartDate" width="150"></el-table-column>
                <el-table-column label="结束时间" prop="ProjectEndDate" width="150"></el-table-column>

                <el-table-column label="操作" align="left" width="580">
                    <template #default="scope">
                        <div style="display:flex;">
                            <el-button v-auth="'order.show'" plain size="small" @click="table_show(scope.row)">查看</el-button>
                            <!-- <el-button v-if="getifShow_Edit('list',scope.row.WorkflowID)" type="primary" plain size="small" :disabled="getifEdit(scope.row)" @click="table_edit(scope.row,[])">编辑</el-button>
                       -->

                            <el-button v-if="!ifshowchildrenrow(scope.row)" v-auth="'order.process'" type="primary" plain size="small" :disabled="getifAccept1(scope.row)" @click="accept1(scope.row)">接收</el-button>
                            <el-button v-if="!ifshowedit(scope.row)" type="primary" plain size="small" :disabled="getifEdit1(scope.row)" @click="table_edit1(scope.row)">
                                <div v-if="scope.row.WorkflowID>2">编制</div>
                                <div v-else>编辑</div>
                            </el-button>

                            <el-popconfirm v-if="!ifshowchildrenrow(scope.row)" title="确定测试吗？" @confirm="test1(scope.row)">
                                <template #reference>
                                    <el-button v-auth="'order.execute'" type="primary" plain size="small" :disabled="getifTest1(scope.row)">
                                        <div>测试</div>
                                    </el-button>
                                </template>
                            </el-popconfirm>

                            <el-popconfirm v-if="!ifshowchildrenrow(scope.row)" title="确定执行吗？" @confirm="execute1(scope.row)">
                                <template #reference>
                                    <el-button v-auth="'order.execute'" type="primary" plain size="small" :disabled="getifExcute1(scope.row)">
                                        <div>执行</div>
                                    </el-button>
                                </template>
                            </el-popconfirm>

                            <el-popconfirm title="确定提交吗？" @confirm="table_submit(scope.row)">
                                <template #reference>
                                    <el-button v-auth="'order.submit'" type="primary" plain size="small" :disabled="scope.row.WorkflowID!='1'">提交</el-button>
                                </template>
                            </el-popconfirm>

                            <el-button v-auth="'order.verify'" type="primary" plain size="small" :disabled="getifVeriy(scope.row)" @click="verify(scope.row)">
                                <div v-if="scope.row.currentVeriyuserType == undefined || scope.row.currentVeriyuserType == 'sh'"> 审核</div>
                                <div v-else>审批</div>
                            </el-button>
                            <!-- <el-button v-auth="'order.process'" type="primary" plain size="small" :disabled="getifAccept(scope.row)" @click="accept(scope.row)">接收</el-button>
                        <el-button v-auth="'order.execute'" type="primary" plain size="small" :disabled="scope.row.Closed=='1'||scope.row.WorkflowID!='3'" @click="execute(scope.row)">执行</el-button> -->
                            <div v-if="scope.row.WorkflowID>1" style="margin-right: 10px;margin-left: 10px;margin-top: -1px;">
                                <el-button v-auth="'order.press'" type="primary" plain size="small" :disabled="scope.row.Closed=='1'" @click="msgClick1(scope.row)">催办</el-button>
                            </div>

                            <el-popconfirm title="确定中止吗？" @confirm="stop(scope.row)">
                                <template #reference>
                                    <el-button v-auth="'order.terminate'" type="warning" :disabled="scope.row.Closed=='1'" plain size="small">中止</el-button>
                                </template>
                            </el-popconfirm>

                            <el-popconfirm title="确定删除吗？" @confirm="deteleRow(scope.row.ProjectID)">
                                <template #reference>
                                    <el-button v-auth="'order.delete'" plain type="danger" size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </div>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <el-container v-if="dialog.save">
        <orderadd ref="saveDialog" @endSave="endSave" @verifyClick="verifyClick" @msgClick="msgClick" @testClick="testClick" @executeClick="executeClick" @stopClick="stopClick" @submitClick="submitClick"></orderadd>
    </el-container>

    <el-dialog v-model="dialog.msg" width="30%" title='发送消息' :close-on-click-modal="false">

        <el-form :model="msgData" ref="msgForm" label-width="80px" :rules="msgRules" label-position="left" status-icon>
            <el-form-item label="接收方" prop="re_user">
                <!-- <el-select v-model="msgData.re_user" class="m-2" placeholder="">
                    <el-option v-for="item in userList" :key="item.value" :label="item.label" :value="item.value" />
                </el-select> -->
                <el-cascader style="width:100%;" :rows="2" v-model="msgData.re_user" :props="userProps" :options="userOptions" :show-all-levels="false" />

            </el-form-item>

            <el-form-item label="内容" prop="content">
                <el-input v-model="msgData.content" :rows="2" type="textarea" placeholder="" />
            </el-form-item>
        </el-form>

        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialog.msg = false">取消</el-button>
                <el-button type="primary" @click="sendMsg">确认</el-button>
            </span>
        </template>
    </el-dialog>

    <el-dialog v-model="dialog.verify" width="30%" title='审核' :close-on-click-modal="false">

        <el-form :model="verifyData" ref="verifyForm" :rules="verifyRules" label-width="80px" label-position="left" status-icon>
            <el-form-item label="是否同意" prop="verifyvalue">
                <el-select v-model="verifyData.verifyvalue" class="m-2" @change="verifyChanged" placeholder="">
                    <el-option v-for="item in verifyoption" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </el-form-item>

            <el-form-item label="审核意见" prop="verifycontent">
                <el-input v-model="verifyData.verifycontent" :rows="2" type="textarea" placeholder="" />
            </el-form-item>
        </el-form>

        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialog .verify=false">取消</el-button>
                <el-button type="primary" @click="confirmVerify">确认</el-button>
            </span>
        </template>
    </el-dialog>

    <el-dialog v-model="dialog.verifyp" width="30%" title='审批' :close-on-click-modal="false">

        <el-form :model="verifypData" ref="verifypForm" :rules="verifypRules" label-width="80px" label-position="left" status-icon>
            <el-form-item label="是否同意" prop="verifypvalue">
                <el-select v-model="verifypData.verifypvalue" class="m-2" @change="verifypChanged" placeholder="">
                    <el-option v-for="item in verifypoption" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </el-form-item>

            <el-form-item label="审批意见" prop="verifypcontent">
                <el-input v-model="verifypData.verifypcontent" :rows="2" type="textarea" placeholder="" />
            </el-form-item>
        </el-form>

        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialog .verifyp=false">取消</el-button>
                <el-button type="primary" @click="confirmVerifyp">确认</el-button>
            </span>
        </template>
    </el-dialog>

    <el-drawer v-model="dialog.info" :size="600" title="基本信息" custom-class="drawerBG" direction="rtl" destroy-on-close>
        <el-card shadow="never">
            <el-descriptions title="" :column="1" border>
                <el-descriptions-item label="调度计划ID" width="150px">{{selectRow['ProjectID']}}</el-descriptions-item>
                <el-descriptions-item label="调度文号" width="150px">{{selectRow['ProjectSerrial']}}</el-descriptions-item>
                <el-descriptions-item label="调度令性质" width="150px">{{selectRow['ProjectType']==0?'试验':'正式'}}</el-descriptions-item>
                <el-descriptions-item label="发送单位" width="150px">{{selectRow['ProjectAuthor']}}</el-descriptions-item>
                <el-descriptions-item label="调度名称" width="150px">{{selectRow['ProjectName']}}</el-descriptions-item>
                <el-descriptions-item label="起草部门" width="150px">{{selectRow['ProjectSenderOrg']}}</el-descriptions-item>
                <el-descriptions-item label="发送人" width="150px">{{selectRow['ProjectSender']}}</el-descriptions-item>
                <el-descriptions-item label="审核人" width="150px">{{selectRow['ProjectAuditor']}}</el-descriptions-item>
                <el-descriptions-item label="审核人2" width="150px">{{selectRow['ProjectAuditor2']}}</el-descriptions-item>

                <el-descriptions-item label="状态" width="150px">
                    <div v-if="selectRow['ProjectStatus']==0">未开始</div>
                    <div v-if="selectRow['ProjectStatus']==1">进行中</div>
                    <div v-if="selectRow['ProjectStatus']==2">结束</div>
                    <div v-if="selectRow['ProjectStatus']==9">终止</div>
                </el-descriptions-item>
                <el-descriptions-item label="开始时间" width="150px">{{selectRow['ProjectStartDate']}}</el-descriptions-item>
                <el-descriptions-item label="结束时间" width="150px">{{selectRow['ProjectEndDate']}}</el-descriptions-item>
                <el-descriptions-item label="系统中流程步骤" width="150px">
                    <div v-if="selectRow['WorkflowID']==1">中心发起</div>
                    <div v-if="selectRow['WorkflowID']==2">中心审核</div>
                    <div v-if="selectRow['WorkflowID']==3">台站接收</div>
                    <div v-if="selectRow['WorkflowID']==4">分配执行</div>
                    <div v-if="selectRow['WorkflowID']==5">执行监控</div>
                    <div v-if="selectRow['WorkflowID']==6">归档</div>
                </el-descriptions-item>

            </el-descriptions>
        </el-card>
    </el-drawer>
</template>

<script setup> 
import scSelectFilter from '@/components/scSelectFilter'
import orderadd from './check'
import { reactive, getCurrentInstance, onMounted, ref, nextTick } from 'vue'
import { ElSlider } from 'element-plus'
const { proxy } = getCurrentInstance()



//#region 变量定义
let currenttime = new Date(new Date().setDate(new Date().getDate() + 30))
let lasttime = new Date(new Date() - 1000 * 60 * 60 * 24 * 30)

let userProps = {
    //expandTrigger: 'hover', 
    multiple: true
}

//审核选项 
let verifyData = reactive({
    verifyvalue: '1',
    verifycontent: '拟同意!'
})
let verifyoption = ref([
    {
        value: '1',
        label: '拟同意',
    },
    {
        value: '0',
        label: '拟不同意',
    }
])
let verifyForm = ref(null)
let verifyRules = reactive({
    verifyvalue: [
        { required: true, message: '请选择是否同意', trigger: 'blur' }
    ],
    verifycontent: [
        { required: true, message: '请填写意见', trigger: 'blur' }
    ],
})

//审批选项 
let verifypData = reactive({
    verifypvalue: '1',
    verifypcontent: '同意!'
})
let verifypoption = ref([
    {
        value: '1',
        label: '同意',
    },
    {
        value: '0',
        label: '不同意',
    }
])
let verifypForm = ref(null)
let verifypRules = reactive({
    verifypvalue: [
        { required: true, message: '请选择是否同意', trigger: 'blur' }
    ],
    verifypcontent: [
        { required: true, message: '请填写意见', trigger: 'blur' }
    ],
})

//发送消息 
let msgData = reactive({
    re_user: '',
    content: ''
})
let msgForm = ref(null)
let msgRules = reactive({
    re_user: [
        { required: true, message: '请选择接收人', trigger: 'blur' }
    ],
    content: [
        { required: true, message: '请填写内容', trigger: 'blur' }
    ],
})

//用户列表
let userList = reactive([])
let userOptions = reactive([])

//弹框控制
let dialog = ref({
    save: false,
    info: false,
    verify: false,
    verifyp: false,
    msg: false
})
//列表选中行
let selectRow = ref({})
//子列表选中行
let selectChildrenRow = ref({})
//新增编辑弹窗对象
let saveDialog = ref(null)
//时间
let time = ref([
    '', ''
    // new Date(lasttime.getFullYear(), lasttime.getMonth(), lasttime.getDate(), lasttime.getHours(), 0, 0),
    // new Date(currenttime.getFullYear(), currenttime.getMonth(), currenttime.getDate(), currenttime.getHours(), 0, 0)
])
//列表查询接口和参数
let list = ref({
    apiObj: proxy.$API.order.list,
    //搜索参数
    params: {
        keyword: '',
        starttime: time.value[0] == '' ? '' : proxy.$TOOL.dateFormat(time.value[0], 'yyyy-MM-dd hh:mm:ss'),
        endtime: time.value[1] == '' ? '' : proxy.$TOOL.dateFormat(time.value[1], 'yyyy-MM-dd hh:mm:ss'),
        status: isNaN(proxy.$route.path.split('/')[proxy.$route.path.split('/').length - 1]) ? -1 : { type: proxy.$route.path.split('/')[proxy.$route.path.split('/').length - 1] }, //状态1-6   -1表示全部
        deptTtype: proxy.$TOOL.data.get("USER_INFO").deptTtype,//部门ID
        deptId: proxy.$TOOL.data.get("USER_INFO").deptId,//部门ID
        userId: proxy.$TOOL.data.get("USER_INFO").userId,//用户ID
    }
})
//列表对象
let table = ref(null)
//状态标签
let filterData = reactive([
    {
        title: "当前状态",
        key: "type",
        multiple: true,
        options: [
            {
                label: "全部",
                value: "-1"
            },
            {
                label: "中心发起",
                value: "1"
            },
            {
                label: "中心审核",
                value: "2"
            },
            {
                label: "台站接收",
                value: "3"
            },
            {
                label: "分配执行",
                value: "4"
            },
            {
                label: "执行监控",
                value: "5"
            }
            ,
            {
                label: "归档",
                value: "6"
            }
        ]
    }
]
)
let filterSelected = ref('-1')
//权限数组
let PERMISSIONS = []
//#endregion

//#region method 

let getrowclassname = (row) => {
    let result = ifshowchildrenrow(row.row)

    if (result)
        return ''
    else
        return 'expandhide'
}

//是否展开显示台站接收情况
let ifshowchildrenrow = (row) => {

    if (row.Closed == '1')
        return true
    else {
        if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心') {
            return true
        }
        else {
            //台站账号的  属于发起人 审核人 签发人 可以看到全部台站接收情况
            if (row.ProjectSender.toString() == proxy.$TOOL.data.get("USER_INFO").userId.toString()
                || row.ProjectAuditor.toString() == proxy.$TOOL.data.get("USER_INFO").userId.toString()
                || row.ProjectAuditor2.toString() == proxy.$TOOL.data.get("USER_INFO").userId.toString()
                || row.ProjectSign.toString() == proxy.$TOOL.data.get("USER_INFO").userId.toString()
            ) {
                return true
            }
            else
                return false
        }

    }

}

//提交审核
let table_submit = async (row) => {

    let result = await proxy.$API.order.submit.post(
        {
            ProjectID: row.ProjectID,
            ProjectAuditor: row.ProjectAuditor,
            ProjectAuditor2: row.ProjectAuditor2,
            ProjectSerrial: row.ProjectSerrial,
            sender: proxy.$TOOL.data.get("USER_INFO").userId
        }
    )

    if (result.code == 200) {
        proxy.$message.success("提交成功")
        dialog.value.verify = false
        upsearch()
        if (saveDialog) {
            dialog.value.save = false
        }
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })
}
let submitClick = async () => {
    await table_submit(selectRow.value)
}
//审核下拉框事件
let verifyChanged = (value) => {
    if (value == '0')
        verifyData.verifycontent = '拟不同意!'
    else
        verifyData.verifycontent = '拟同意!'
}
//审批下拉框事件
let verifypChanged = (value) => {
    if (value == '0')
        verifypData.verifypcontent = '不同意!'
    else
        verifypData.verifypcontent = '同意!'
}
//催办发送消息
let sendMsg = async () => {

    msgForm.value.validate(async (valid) => {
        if (valid) {
            let _obj = JSON.stringify(msgData)
            let newdata = JSON.parse(_obj)
            newdata.type = 'cb'
            newdata.sender = proxy.$TOOL.data.get("USER_INFO").userId
            newdata.ProjectID = selectRow.value.ProjectID

            let result = await proxy.$API.system.message.sendMsg.post(newdata)

            if (result.code == 200) {
                proxy.$message.success("发送成功")
                dialog.value.msg = false
            }
            else
                proxy.$alert(result.message, "异常", { type: 'error' })
        } else {
            proxy.$alert("请正确填写！", "提示", { type: 'error' })
            return false;
        }
    })

}
let msgClick1 = (row) => {
    selectRow.value = row
    dialog.value.msg = true

    msgData.re_user = ''
    msgData.content = ''
}
let msgClick = () => {
    dialog.value.msg = true

    msgData.re_user = ''
    msgData.content = ''
}

//判断当前账户下是否可以审核
let getifVeriy = (row) => {

    if (row.Closed == '1' || row.ProjectVerify == '1' || row.WorkflowID == '1')
        return true
    else {

        if (row.currentVeriyuserId == proxy.$TOOL.data.get("USER_INFO").userId)
            return false
        else
            return true
    }

}

//判断当前账户下是否已经接收过
let getifAccept = (row, childrenrow) => {

    if (row.Closed == '1')
        return true
    else {
        if (row.ProjectVerify == '1') {
            if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心') {
                if (childrenrow.statue == '已接收')
                    return true
                else
                    return false
            }
            else {
                let result = false
                if (childrenrow.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                    if (childrenrow.statue == '已接收')
                        result = true
                    else
                        result = false
                }
                else
                    result = true


                return result
            }
        }
        else
            return true

    }

}
let getifAccept1 = (row) => {

    if (row.Closed == '1')
        return true
    else {
        if (row.ProjectVerify == '1') {
            if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心') {
                // if (childrenrow.statue == '已接收')
                //     return true
                // else
                //     return false
            }
            else {
                let result = false
                if (row.children.length > 0) {
                    row.children.forEach(element => {
                        if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {

                            if (element.statue == '已接收')
                                result = true
                            else
                                result = false

                        }

                    });
                }

                return result
            }
        }
        else
            return true

    }

}

//判断当前账户下点击可以测试
let getifTest = (row, childrenrow) => {

    if (row.Closed == '1')
        return true
    else {

        if (row.ProjectVerify == '1') {//审核通过并且在第3步且已经被接收的才能点击测试按钮 && row.WorkflowID == '4'
            if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心')
                if (childrenrow.statue == '已接收') {
                    if (childrenrow.testUser == undefined || childrenrow.testUser == '')
                        return false
                    else
                        return true
                }
                else
                    return true

            else {
                let result = false
                if (childrenrow.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                    if (childrenrow.statue == '已接收') {
                        if (childrenrow.testUser == undefined || childrenrow.testUser == '')
                            result = false
                        else
                            result = true
                    }
                    else
                        return true
                }
                else
                    result = true


                return result
            }

        }
        else
            return true

    }

}
let getifTest1 = (row) => {

    if (row.Closed == '1')
        return true
    else {

        if (row.ProjectVerify == '1') {//审核通过并且在第3步且已经被接收的才能点击执行按钮 && row.WorkflowID == '4'
            if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心')
                return
            else {

                if (row.children != undefined) {
                    let result = false
                    let childrenrow = {}
                    if (row.children.length > 0) {
                        row.children.forEach(element => {
                            if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                                childrenrow = element
                            }

                        });
                    }

                    if (childrenrow.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                        if (childrenrow.statue == '已接收') {
                            if (childrenrow.testUser == undefined || childrenrow.testUser == '')
                                result = false
                            else
                                result = true
                        }
                        else
                            return true
                    }
                    else
                        result = true


                    return result
                }
                else
                    return false
            }
        }
        else
            return true

    }

}


//判断当前账户下点击可以执行
let getifExcute = (row, childrenrow) => {

    if (row.Closed == '1')
        return true
    else {

        if (row.ProjectVerify == '1') {//审核通过并且在第3步且已经被接收的才能点击执行按钮 && row.WorkflowID == '4'
            if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心')
                if (childrenrow.statue == '已接收') {
                    if ((childrenrow.executeUser == undefined || childrenrow.executeUser == '') && (childrenrow.testUser != ''))
                        return false
                    else
                        return true
                }
                else
                    return true

            else {
                let result = false
                if (childrenrow.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                    if (childrenrow.statue == '已接收') {
                        if ((childrenrow.executeUser == undefined || childrenrow.executeUser == '') && (childrenrow.testUser != ''))
                            result = false
                        else
                            result = true
                    }
                    else
                        return true
                }
                else
                    result = true


                return result
            }

        }
        else
            return true

    }

}
let getifExcute1 = (row) => {

    if (row.Closed == '1')
        return true
    else {

        if (row.ProjectVerify == '1') {//审核通过并且在第3步且已经被接收的才能点击执行按钮 && row.WorkflowID == '4'
            if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心')

                return

            else {

                if (row.children != undefined) {
                    let result = false
                    let childrenrow = {}
                    if (row.children.length > 0) {
                        row.children.forEach(element => {
                            if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                                childrenrow = element
                            }

                        });
                    }

                    if (childrenrow.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                        if (childrenrow.statue == '已接收') {
                            if ((childrenrow.executeUser == undefined || childrenrow.executeUser == '') && (childrenrow.testUser != ''))
                                result = false
                            else
                                result = true
                        }
                        else
                            return true
                    }
                    else
                        result = true


                    return result
                }
                else
                    return false
            }
        }
        else
            return true

    }

}

//判断当前账户下是否已接收可编辑
let getifEdit = (row, childrenrow) => {

    if (row.Closed == '1')
        return true
    else if (row.WorkflowID == '1')
        return false
    else if (row.WorkflowID == '2')
        return true
    else if (row.WorkflowID > 4)
        return true
    else if (row.ProjectVerify != null && row.ProjectVerify != '1')
        return true
    else {
        if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心')
            return false
        else {
            if (childrenrow.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                if (row.children != undefined) {
                    if (row.children.length > 0) {
                        let result = false
                        row.children.forEach(element => {
                            if (proxy.$TOOL.data.get("USER_INFO").deptId.toString() == element.stationID.toString() && element.statue == '已接收') {
                                result = true
                            }
                        });

                        return !result
                    }
                    else
                        return true
                }
                else
                    return true
            }
            else
                return true

        }
    }
}
let getifEdit1 = (row) => {

    if (row.Closed == '1')
        return true
    else if (row.WorkflowID == '1')
        return false
    else if (row.WorkflowID == '2')
        return true
    else if (row.WorkflowID > 4)
        return true
    else if (row.ProjectVerify != null && row.ProjectVerify != '1')
        return true
    else {
        if (proxy.$TOOL.data.get("USER_INFO").deptTtype == '中心')
            return false
        else {
            if (row.children != undefined) {
                let childrenrow = {}
                if (row.children.length > 0) {
                    row.children.forEach(element => {
                        if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                            childrenrow = element
                        }

                    });
                }
                else
                    return false
                if (childrenrow.stationID == undefined)
                    return false
                else {
                    if (childrenrow.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                        if (row.children != undefined) {
                            if (row.children.length > 0) {
                                let result = false
                                row.children.forEach(element => {
                                    if (proxy.$TOOL.data.get("USER_INFO").deptId.toString() == element.stationID.toString() && element.statue == '已接收') {
                                        result = true
                                    }
                                });

                                return !result
                            }
                            else
                                return true
                        }
                        else
                            return true
                    }
                    else
                        return true
                }
            }
            else
                return false
        }
    }
}

//判断主表是否显示编辑按钮
let ifshowedit = (row) => {
    if (row.wodkflowid < 2 && PERMISSIONS.includes('order.process'))
        return true
    else {
        return ifshowchildrenrow(row)
    }
}

//判断当前账户是否显示编辑按钮
let getifShow_Edit = (type, wodkflowid) => {

    if (PERMISSIONS.length == 0)
        return
    if (type == 'list')//主表的按钮
    {

        if (wodkflowid < 2 && PERMISSIONS.includes('order.process'))
            return true
        else
            return false
    }
    else {
        //子表的按钮
        if (wodkflowid >= 3 && PERMISSIONS.includes('order.process'))
            return true
        else
            return false
    }

}

//判断当前账户下是否有审核的权利
let getifVerify = (row) => {

    if (row.Closed == '1')
        return true
    else if (row.ProjectVerify == '1')
        return true
    else {
        if (proxy.$TOOL.data.get("USER_INFO").userId == row.ProjectAuditor || proxy.$TOOL.data.get("USER_INFO").userId == row.ProjectAuditor2)
            return false
        else
            return true
    }
}

//列表查询函数
let upsearch = () => {
    list.value.params.starttime = time.value[0] == '' ? '' : proxy.$TOOL.dateFormat(time.value[0], 'yyyy-MM-dd hh:mm:ss')
    list.value.params.endtime = time.value[1] == '' ? '' : proxy.$TOOL.dateFormat(time.value[1], 'yyyy-MM-dd hh:mm:ss')

    table.value.upData(list.value.params)
}

//状态选择tag事件
let filterChange = (data) => {

    let re = {}
    Object.assign(re, data)

    list.value.params.status = re

    table.value.upData(list.value.params)
}

//查看
let table_show = (row) => {
    selectRow.value = row
    let _obj = JSON.stringify(selectRow.value)
    let newdata = JSON.parse(_obj)
    dialog.value.save = true
    newdata.readonly = true
    nextTick(() => {
        setTimeout(() => {
            saveDialog.value.setValue(newdata)
        }, 100);

    })

}

//审核按钮
let verify = (row) => {
    if (proxy.$TOOL.data.get("USER_INFO").userId == row.ProjectAuditor || proxy.$TOOL.data.get("USER_INFO").userId == row.ProjectAuditor2 || proxy.$TOOL.data.get("USER_INFO").userId == row.ProjectSign) {
        selectRow.value = row
        if (row.currentVeriyuserType == 'sh') {

            dialog.value.verify = true
            nextTick(() => {
                verifyData.verifyvalue = '1'
                verifyData.verifycontent = '拟同意!'
            })
        }
        else {
            dialog.value.verifyp = true
            nextTick(() => {
                verifypData.verifypvalue = '1'
                verifypData.verifypcontent = '同意!'
            })
        }

    }
    else
        proxy.$alert('您不是指定的审核人!', "异常", { type: 'error' })
}
let verifyClick = () => {

    if (proxy.$TOOL.data.get("USER_INFO").userId == selectRow.value.ProjectAuditor || proxy.$TOOL.data.get("USER_INFO").userId == selectRow.value.ProjectAuditor2 || proxy.$TOOL.data.get("USER_INFO").userId == selectRow.value.ProjectSign) {

        // dialog.value.verify = true
        // nextTick(() => {

        // })
        if (selectRow.value.currentVeriyuserType == 'sh') {

            dialog.value.verify = true
            nextTick(() => {
                verifyData.verifyvalue = '1'
                verifyData.verifycontent = '拟同意!'
            })
        }
        else {
            dialog.value.verifyp = true
            nextTick(() => {
                verifypData.verifypvalue = '1'
                verifypData.verifypcontent = '同意!'
            })
        }
    }
    else
        proxy.$alert('您不是指定的审核人!', "异常", { type: 'error' })
}
//审核确认
let confirmVerify = async () => {
    verifyForm.value.validate(async (valid) => {
        if (valid) {
            let content = verifyData.verifyvalue == '1' ? '拟同意' : '拟不同意'
            let result = await proxy.$API.order.verify.post(
                {
                    ProjectID: selectRow.value.ProjectID,
                    ProjectSerrial: selectRow.value.ProjectSerrial,
                    sender: proxy.$TOOL.data.get("USER_INFO").userId,
                    content: verifyData.verifycontent,
                    ifthroug: verifyData.verifyvalue,
                    stationIds: selectRow.value.stationIds,
                    type: '审核',
                    actime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
                }
            )

            if (result.code == 200) {
                proxy.$message.success("审核成功")
                dialog.value.verify = false
                upsearch()
                if (saveDialog) {
                    // saveDialog.value.getFlow()
                    dialog.value.save = false
                }
            }
            else
                proxy.$alert(result.message, "异常", { type: 'error' })
        }
    })
}
//审批确认
let confirmVerifyp = async () => {
    verifypForm.value.validate(async (valid) => {
        if (valid) {
            let content = verifypData.verifypvalue == '1' ? '同意' : '不同意'
            let result = await proxy.$API.order.verify.post(
                {
                    ProjectID: selectRow.value.ProjectID,
                    ProjectSerrial: selectRow.value.ProjectSerrial,
                    sender: proxy.$TOOL.data.get("USER_INFO").userId,
                    content: verifypData.verifypcontent,
                    ifthroug: verifypData.verifypvalue,
                    stationIds: selectRow.value.stationIds,
                    type: '审批',
                    actime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
                }
            )

            if (result.code == 200) {
                proxy.$message.success("审批成功")
                dialog.value.verifyp = false
                upsearch()
                if (saveDialog) {
                    // saveDialog.value.getFlow()
                    dialog.value.save = false
                }
            }
            else
                proxy.$alert(result.message, "异常", { type: 'error' })
        }
    })
}

//台站接收
let accept = async (row, childrenrow) => {
    selectRow.value = row

    let result = await proxy.$API.order.accept.post(
        {
            ProjectID: selectRow.value.ProjectID,
            sender: proxy.$TOOL.data.get("USER_INFO").userId,
            stationIds: selectRow.value.stationIds,
            stationID: childrenrow.stationID,
            actime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
        }
    )
    if (result.code == 200) {
        proxy.$message.success("接收成功")
        if (result.WorkflowID != undefined)
            selectRow.value.WorkflowID = result.WorkflowID

        table.value.tableData.forEach(element => {
            if (element.ProjectID == selectRow.value.ProjectID) {
                element.children.forEach(chirld => {
                    if (chirld.stationID == childrenrow.stationID) {
                        chirld.acceptTime = proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
                        chirld.acceptUser = proxy.$TOOL.data.get("USER_INFO").userId
                        chirld.acceptUserName = proxy.$TOOL.data.get("USER_INFO").name
                        chirld.statue = '已接收'
                    }
                });


            }
        });
        //upsearch()
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })
}
let accept1 = async (row) => {
    selectRow.value = row

    let childrenrow = {}
    if (row.children != undefined) {
        if (row.children.length > 0) {
            row.children.forEach(element => {
                if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                    childrenrow = element
                }

            });
        }
        else
            return

        let result = await proxy.$API.order.accept.post(
            {
                ProjectID: selectRow.value.ProjectID,
                sender: proxy.$TOOL.data.get("USER_INFO").userId,
                stationIds: selectRow.value.stationIds,
                stationID: childrenrow.stationID,
                actime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
            }
        )
        if (result.code == 200) {
            proxy.$message.success("接收成功")
            if (result.WorkflowID != undefined)
                selectRow.value.WorkflowID = result.WorkflowID

            table.value.tableData.forEach(element => {
                if (element.ProjectID == selectRow.value.ProjectID) {
                    element.children.forEach(chirld => {
                        if (chirld.stationID == childrenrow.stationID) {
                            chirld.acceptTime = proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
                            chirld.acceptUser = proxy.$TOOL.data.get("USER_INFO").userId
                            chirld.acceptUserName = proxy.$TOOL.data.get("USER_INFO").name
                            chirld.statue = '已接收'
                        }
                    });


                }
            });
            //upsearch()
        }
        else
            proxy.$alert(result.message, "异常", { type: 'error' })
    }
    else
        return
}

//测试
let test = async (row, childrenrow) => {

    let result = await proxy.$API.order.test.post(
        {
            ProjectID: row.ProjectID,
            sender: proxy.$TOOL.data.get("USER_INFO").userId,
            stationID: childrenrow.stationID,
            content: '',
            extime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
        }
    )
    if (result.code == 200) {
        proxy.$message.success("测试成功")
        upsearch()
        if (saveDialog) {
            dialog.value.save = false
        }
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })

}
let test1 = async (row) => {

    let childrenrow = {}
    if (row.children.length > 0) {
        row.children.forEach(element => {
            if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                childrenrow = element
            }

        });
    }
    else
        return

    let result = await proxy.$API.order.test.post(
        {
            ProjectID: row.ProjectID,
            sender: proxy.$TOOL.data.get("USER_INFO").userId,
            stationID: childrenrow.stationID,
            content: '',
            extime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
        }
    )
    if (result.code == 200) {
        proxy.$message.success("操作成功")

        upsearch()
        if (saveDialog) {
            dialog.value.save = false
        }
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })

}
let testClick = async () => {
    await test(selectRow.value, selectChildrenRow.value)
}

//执行
let execute = async (row, childrenrow) => {

    let result = await proxy.$API.order.execute.post(
        {
            ProjectID: row.ProjectID,
            sender: proxy.$TOOL.data.get("USER_INFO").userId,
            stationID: childrenrow.stationID,
            content: '',
            extime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
        }
    )
    if (result.code == 200) {
        proxy.$message.success("操作成功")
        if (result.WorkflowID != undefined)
            selectRow.value.WorkflowID = result.WorkflowID

        upsearch()
        if (saveDialog) {
            dialog.value.save = false
        }
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })

}
let execute1 = async (row) => {

    let childrenrow = {}
    if (row.children.length > 0) {
        row.children.forEach(element => {
            if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                childrenrow = element
            }

        });
    }
    else
        return

    let result = await proxy.$API.order.execute.post(
        {
            ProjectID: row.ProjectID,
            sender: proxy.$TOOL.data.get("USER_INFO").userId,
            stationID: childrenrow.stationID,
            content: '',
            extime: proxy.$TOOL.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
        }
    )
    if (result.code == 200) {
        proxy.$message.success("操作成功")
        if (result.WorkflowID != undefined)
            selectRow.value.WorkflowID = result.WorkflowID

        upsearch()
        if (saveDialog) {
            dialog.value.save = false
        }
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })

}
let executeClick = async () => {
    await execute(selectRow.value, selectChildrenRow.value)
}

//中止
let stop = async (row) => {

    let result = await proxy.$API.order.stop.post(
        {
            ProjectID: row.ProjectID,
            sender: proxy.$TOOL.data.get("USER_INFO").userId,
            content: ''
        }
    )
    if (result.code == 200) {
        proxy.$message.success("操作成功")

        upsearch()
        if (saveDialog) {
            dialog.value.save = false
        }
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })

}
let stopClick = async (row) => {

    await stop(selectRow.value)

}


//窗口编辑
let table_edit = (row, childrenrow) => {

    selectChildrenRow.value = childrenrow
    selectRow.value = row
    let _obj = JSON.stringify(selectRow.value)
    let newdata = JSON.parse(_obj)
    newdata.selectChildrenRow = JSON.parse(JSON.stringify(childrenrow))
    dialog.value.save = true

    nextTick(() => {
        setTimeout(() => {
            saveDialog.value.setValue(newdata)
        }, 100);
        // saveDialog.value.setValue(newdata)
    })
}
let table_edit1 = (row) => {
    let childrenrow = {}
    if (!ifshowchildrenrow(row))
        if (row.children.length > 0) {
            row.children.forEach(element => {
                if (element.stationID.toString() == proxy.$TOOL.data.get("USER_INFO").deptId.toString()) {
                    childrenrow = element
                }
            });
        }

    selectChildrenRow.value = childrenrow
    selectRow.value = row
    let _obj = JSON.stringify(selectRow.value)
    let newdata = JSON.parse(_obj)
    newdata.selectChildrenRow = JSON.parse(JSON.stringify(childrenrow))
    dialog.value.save = true

    nextTick(() => {
        setTimeout(() => {
            saveDialog.value.setValue(newdata)
        }, 100);
        // saveDialog.value.setValue(newdata)
    })
}


//窗口新增
let orderAdd = () => {
    dialog.value.save = true
    nextTick(() => {
        saveDialog.value.setValue({ ProjectID: -1 })
        saveDialog.value.pageRset()
    })
}

//窗口关闭
let onbeforeClose = (done) => {
    saveDialog.value.pageRset()
    done
}

//保存成功
let endSave = () => {
    dialog.value.save = false

    table.value.refresh()
}

//删除
let deteleRow = async (id) => {

    let result = await proxy.$API.order.delete.post({ id: id })
    if (result.code == 200) {
        proxy.$message.success("删除成功")

        table.value.refresh()
    }
    else
        proxy.$alert(result.message, "异常", { type: 'error' })
}

//初始化
onMounted(async () => {

    PERMISSIONS = proxy.$TOOL.data.get("PERMISSIONS")


    let statu = proxy.$route.path.split('/')[proxy.$route.path.split('/').length - 1]

    if (!isNaN(statu)) {


        filterData[0].options.forEach(element => {
            if (element.value == statu.toString()) {
                element.disabled = false
            }
            else
                element.disabled = true
        });
    }
    let user = await proxy.$API.system.user.all.get()
    userList.push(...user.data)

    let usertree = await proxy.$API.system.user.tree.get()

    userOptions.push(...usertree.data)

})



//#endregion
</script>
<style>
.expandhide .el-table__expand-column .cell .el-table__expand-icon {
    display: none !important;
}
</style>
<style lang="scss" scoped>
// ::v-deep .el-table__expand-icon {
//     display: none;
// }
.elheader {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    height: 120px !important;
    .left-panel {
        width: 100%;
    }
    .title {
        color: green;
        padding-left: 10px;
        padding-top: 10px;
    }
    .name {
        margin-left: 10px;
    }
    .fieldname {
        margin-left: 40px;
        margin-right: 10px;
    }
    .tags {
        margin-left: 10px;
        width: 100%;
        height: 50px;
    }
}
</style>
